<?php
namespace app\super\controller;
use think\Db;
use app\super\validate\StudyValidate;
class StudyController extends CommonController {
    /**
     * 获取课程数据
     */
    public function getStudyInfo(){
        $where = '';
        $rows = $_POST['rows'];
        $page = $_POST['page'];
        if($_POST['keyword']!=''){
            $keyword = $_POST['keyword'];
            $where['a.project_name|a.project_teacher_name|ut.team_name|ut.team_number'] = array('like',"%$keyword%");
        }
        if($_POST['project_type']!=''){//课程类型
        $where['a.project_type'] = $_POST['project_type'];
        }
        if($_POST['project_release']!=''){//状态
            $where['a.project_release'] = $_POST['project_release'];
        }
        if($_POST['start']!=''){//时间
            $where['a.project_time'] =array('>=',$_POST['start']);
        }elseif ($_POST['end']!=''){
            $where['a.project_time'] =array('<=',$_POST['end']);
        }elseif ($_POST['start']!=''&&$_POST['end']!=''){
            $where['a.project_time'] =array('between',array($_POST['start'],$_POST['end']));
        }
        if($_POST['type']==1){
            $where['project_banner_img'] = array('NEQ','is not null');
        }else if($_POST['type']==2){
            $where['project_main_img'] =array('NEQ','is not null');
        }

        $res = Db::table('up_project')->alias('a')
                              ->join('up_u_user u','u.user_id = a.project_release_user_id','left')
                              ->join('up_team ut','ut.team_id = a.project_team_id','left')
                              ->join('up_u_admin uua','uua.user_id = a.project_release_user_id','left')
                              ->where($where)
                              ->limit($rows * ($page - 1), $rows)
                              ->field('u.user_username,a.*,ut.team_name,ut.team_number,uua.user_username as username')
                              ->order('a.project_time DESC')
                              ->select();
        $total = Db::table('up_project')->alias('a')
            ->join('up_u_user u','u.user_id=a.project_release_user_id')
            ->join('up_team ut','ut.team_id = a.project_team_id','left')
            ->where($where)
            ->count();
        $data['total'] = $total;
        $data['rows'] = $res;
        return json_encode($data);
    }

    /**
     * 发布
     */
    public function Confirmation(){
        $cid = $_POST['cid'];
        if($cid!=''){
            $where['project_id'] = $cid;
            $data['project_release'] = 1;//审核通过
            $res =  Db::table('up_project')->where($where)->update($data);
            if($res){
                $returnData['status'] = 1;
                $returnData['msg'] = "发布成功";
                return json_encode($returnData);
            }else{
                $returnData['status'] = 0;
                $returnData['msg'] = "发布失败";
                return json_encode($returnData);
            }
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "传递参数错误";
            return json_encode($returnData);
        }
    }
    /***
     * 取消发布
     */
    public function QxConfirmation(){
        $cid = $_POST['cid'];
        if($cid!=''){
            $where['project_id'] = $cid;
            $data['project_release'] = 2;//审核通过
            $res =  Db::table('up_project')->where($where)->update($data);
            if($res){
                $returnData['status'] = 1;
                $returnData['msg'] = "取消发布成功";
                return json_encode($returnData);
            }else{
                $returnData['status'] = 0;
                $returnData['msg'] = "取消发布失败";
                return json_encode($returnData);
            }
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "传递参数错误";
            return json_encode($returnData);
        }
    }
    /**
     * 删除此课程
     */
    public function delConfirmation(){
        $cid = $_POST['cid'];
        if($cid!=''){
            Db::startTrans();//开启事物
            $where['project_id'] = $cid;
            $res =  Db::table('up_project')->where($where)->delete();
            $whereMap['catalog_project_id'] = $cid;
            $data = Db::table('up_project_catalog')->where($whereMap)->column('catalog_id');
             Db::table('up_project_catalog')->where($whereMap)->delete();
            foreach ($data as $key=>$vo){
                $map['up_course_catalog_id'] = $vo;
                Db::table('up_project_catalog_course')->where($map)->delete();
            }
            if($res){
                Db::commit();//提交事物
                $returnData['status'] = 1;
                $returnData['msg'] = "删除成功";
                return json_encode($returnData);
            }else{
                Db::rollback();//回滚
                $returnData['status'] = 0;
                $returnData['msg'] = "删除失败";
                return json_encode($returnData);
            }
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "传递参数错误";
            return json_encode($returnData);
        }
    }

    /**
     * 添加页面
     */
    public function addStudy(){
//        $data = array(
//            1=>'Banner课程(360*150)',
//            2=>'课程(115*85)'
//        );
//        $data_type = array(
//            1=>'团队课程',
//            2=>'公共课程'
//        );
        $res = array();
//        $this->assign('data',$data);
//        $this->assign('data_type',$data_type);
        $team_id = Db::table('up_team')->where('is_team',1)->column('team_id');
        $team= Db::table('up_team')->where('is_team',1)->field('team_id,team_name')->select();
        $this->assign('team',$team);
        if(count($team_id)>0){
            $where['team_id'] = array('IN',$team_id);
            $res = Db::table('up_team_members')->alias('a')
                                        ->join('up_u_user uuu','uuu.user_id = a.team_member_user_id')
                                        ->field('uuu.user_id,uuu.user_phone,uuu.user_username')
                                        ->where($where)
                                        ->select();
        }
        $this->assign('res',$res);
        return $this->fetch('study/addStudy');
    }

    /**
     * @return string
     * 添加操作
     */
    public function insert(){
        $validata = new StudyValidate();
        if(!$validata->check($_POST)){
            $returnData['status'] = 0;
            $returnData['msg'] = $validata->getError();
            return json_encode($returnData);
        }else{
            if($_FILES['fileImg']['name']=='') {
                $returnData['status'] = 0;
                $returnData['msg'] = "上传文件格式不能为空";
                return json_encode($returnData);
            }
            if($_FILES['file']['name']=='') {
                $returnData['status'] = 0;
                $returnData['msg'] = "上传文件格式不能为空";
                return json_encode($returnData);
            }
            $rand = date('YmdHis').rand(100000,999999);
            $exe = explode('.',$_FILES['fileImg']['name']);
            $filePath = $_FILES['fileImg']['tmp_name'];
            $info = $this->qnCommon(2,$rand,$exe[1],$filePath);
            if($info['status']!=200) {
                $returnData['status'] = 0;
                $returnData['msg'] = "上传文件格式不正确";
                return json_encode($returnData);
            }

            $rands = date('YmdHis').rand(100000,999999);
            $exes = explode('.',$_FILES['file']['name']);
            $filePaths = $_FILES['file']['tmp_name'];

            $infos = $this->qnCommon(2,$rands,$exes[1],$filePaths);
            if($infos['status']!=200) {
                $returnData['status'] = 0;
                $returnData['msg'] = "上传文件格式不正确";
                return json_encode($returnData);
            }

            $data['project_id'] = $this->getRandChar(32);
            $data['project_introduction'] = $_POST['project_introduction'];
            $data['project_name'] =  $_POST['project_name'];
            $data['project_teacher_introduction'] = $_POST['project_teacher_name'];
            $data['project_teacher_name'] = $_POST['project_teacher_name'];
            $data['project_teacher_img'] = QiNiu.$infos['key'];
            $data['project_type'] = $_POST['project_type'];
            if($_POST['type_img']==1){
                $data['project_banner_img'] = QiNiu.$info['key'];
            }else{
                $data['project_main_img'] = QiNiu.$info['key'];
            }
            $data['project_time'] = date('Y-m-d H:i:s');
            $data['project_release_user_id'] = session('loginSession')['user_id'];//发布人
            $data['project_release'] = 1;//直接发布
            $res = Db::table('up_project')->insert($data);
            if($res){
                return json_encode(array("status" => 1, "msg" => "发布成功！"));
            }else{
                return json_encode(array("status" => 0, "msg" => "发布失败！"));
            }
        }

    }

    /*
     * 编辑页面
     */
    public function updatenotice()
    {
        $cid = $_POST['nid'];
        $where['project_id'] = $cid;
        $res = Db::table('up_project')->alias('a')
        ->join('up_u_user u','u.user_id = a.project_release_user_id','left')
        ->where($where)
        ->field('u.user_username,a.*')
        ->find();
        $data = array(
//            1=>'Banner课程(360*150)',
            2=>'课程(115*85)'
        );
        $data_type = array(
            1=>'团队课程',
            2=>'公共课程'
        );
        $this->assign('data',$data);
        $this->assign('data_type',$data_type);
        $this->assign('res',$res);
        return $this->fetch('study/updatenotice');
    }
    /**
     * 编辑功能
     */
    public function updateStudy(){
        $validata = new StudyValidate();
        if(!$validata->check($_POST)){
            $returnData['status'] = 0;
            $returnData['msg'] = $validata->getError();
            return json_encode($returnData);
        }else{
            if(!empty($_FILES['fileImg']['type'])){
                    $rand = date('YmdHis').rand(100000,999999);
                    $exe = explode('.',$_FILES['fileImg']['name']);
                    $filePath = $_FILES['fileImg']['tmp_name'];
                    $info = $this->qnCommon(2,$rand,$exe[1],$filePath);
                    if($info['status']!=200) {
                        $returnData['status'] = 0;
                        $returnData['msg'] = "上传文件格式不正确";
                        return json_encode($returnData);
                    }
                    if($_POST['type']==1){//banner图
                        $data['project_banner_img'] = QiNiu.$info['key'];
                        $data['project_main_img'] = '';
                    }else{//图像
                        $data['project_main_img'] = QiNiu.$info['key'];
                        $data['project_banner_img'] = '';
                    }
            }else{
                $res1 = Db::table('up_project')->where('project_id',$_POST['project_id'])->field('project_main_img,project_banner_img,project_type')->find();
                if($_POST['type']==1){//banner图像
                    if($res1['project_banner_img']==''){
                        $data['project_banner_img'] = $res1['project_main_img'];
                        $data['project_main_img'] = '';
                    }
                }else{
                    if($res1['project_main_img']==''){
                        $data['project_main_img'] = $res1['project_banner_img'];
                        $data['project_banner_img'] = '';
                    }
                }
            }
            if(!empty($_FILES['file']['type'])){
                //讲师头像
                $rands = date('YmdHis').rand(100000,999999);
                $exes = explode('.',$_FILES['file']['name']);
                $filePaths = $_FILES['file']['tmp_name'];

                $infos = $this->qnCommon(2,$rands,$exes[1],$filePaths);
                if($infos['status']!=200) {
                    $returnData['status'] = 0;
                    $returnData['msg'] = "上传文件格式不正确";
                    return json_encode($returnData);
                }else{
                    $data['project_teacher_img'] = QiNiu.$infos['key'];

                }
            }

            $data['project_introduction'] = $_POST['project_introduction'];
            $data['project_name'] =  $_POST['project_name'];
            $data['project_teacher_introduction'] = $_POST['project_teacher_name'];
            $data['project_teacher_name'] = $_POST['project_teacher_name'];
            $data['project_type'] = $_POST['project_type'];
            $data['project_release'] = 1;//直接发布
            $whereProject['project_id'] = $_POST['project_id'];
            $res = Db::table('up_project')->where($whereProject)->update($data);
            if($res){
                return json_encode(array("status" => 1, "msg" => "修改成功！"));
            }else{
                return json_encode(array("status" => 0, "msg" => "修改失败！"));
            }
        }

    }


    /**
     * 获取发布目录信息
     */
    public function getCatalog(){
        if($_POST['keyword']!=''){
            $keyword  = $_POST['keyword'];
            $whereMap['a.catalog_name'] = array('like',"%$keyword%");
        }
        $rows = $_POST['rows'];
        $page = $_POST['page'];
        $whereMap['up.project_status'] = 1;//审核通过
        $whereMap['up.project_release'] = 1;//发布成功
        $whereMap['a.catalog_project_id'] = $_POST['project_id'];//发布成功
        $result = Db::table('up_project_catalog')->alias('a')
            ->join('up_project up','up.project_id = a.catalog_project_id','left')
            ->join('up_u_user uuu','uuu.user_id=up.project_release_user_id','left')
            ->join('up_team ut','ut.team_id=up.project_team_id','left')
            ->join('up_u_admin uua','uua.user_id = up.project_release_user_id','left')
            ->where($whereMap)
            ->field('a.*,up.project_name,uuu.user_username,ut.team_name,uua.user_username as username,up.project_id')
            ->limit($rows * ($page - 1), $rows)
            ->select();

        $total = Db::table('up_project_catalog')->alias('a')
                ->join('up_project up','up.project_id = a.catalog_project_id','left')
                ->join('up_u_user uuu','uuu.user_id=up.project_release_user_id','left')
                ->join('up_team ut','ut.team_id=up.project_team_id','left')
                ->join('up_u_admin uua','uua.user_id = up.project_release_user_id','left')

            ->where($whereMap)
            ->count();
        $data['total'] = $total;
        $data['rows'] = $result;
        return json_encode($data);
    }

    /**
     * 删除课程目录
     */
    public function delCatalog(){
        $cid = $_POST['cid'];
        if($cid!=''){
            Db::startTrans();//开启事物
            $whereMap['catalog_id'] = $cid;
            $data = Db::table('up_project_catalog')->where($whereMap)->delete();
            $map['up_course_catalog_id'] = $cid;
            Db::table('up_project_catalog_course')->where($map)->delete();
            if($data){
                Db::commit();//提交事物
                $returnData['status'] = 1;
                $returnData['msg'] = "删除成功";
                return json_encode($returnData);
            }else{
                Db::rollback();//回滚
                $returnData['status'] = 0;
                $returnData['msg'] = "删除失败";
                return json_encode($returnData);
            }
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "传递参数错误";
            return json_encode($returnData);
        }
    }

    /**
     * 添加页面
     */
    public function addCatalog(){
        $res = array();
//        $uid = session('loginSession')['user_id'];
        $where['project_status'] = 1;//审核通过
        $where['project_release'] = 1;//发布成功
//        $where['project_release_user_id'] = $uid;//发布成功
        $where['project_id'] = $_POST['project_id'];//发布成功
        $data  = Db::table('up_project')->where($where)->field('project_id,project_name')->find();
        $team_id = Db::table('up_team')->where('is_team',1)->column('team_id');
        if(count($team_id)>0){
            $where['team_id'] = array('IN',$team_id);
            $res = Db::table('up_team_members')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.team_member_user_id')
                ->field('uuu.user_id,uuu.user_phone,uuu.user_username')
                ->where($where)
                ->select();
        }
        $this->assign('res',$res);
        $this->assign('data',$data);
        return $this->fetch('study/addCatalog');
    }

    /**
     * 添加功能
     */
    public function insertCatalog(){
//        $uid = session('loginSession')['user_id'];
        $where['project_id'] = $_POST['catalog_project_id'];
        if($_POST['catalog_name']==''){
            $returnData['status'] = 0;
            $returnData['msg'] = "课程目录不能为空";
            return json_encode($returnData);
        }
        $data['catalog_id'] = $this->getRandChar(32);
        $data['catalog_project_id'] = $_POST['catalog_project_id'];
        $data['catalog_name'] = $_POST['catalog_name'];
        $data['catalog_time'] = date('Y-m-d H:i:s');

        $result = Db::table('up_project_catalog')->insert($data);
        if ($result) {
            return json_encode(array("status" => 1, "msg" => "课程目录添加成功！"));
        } else {
            return json_encode(array("status" => 0, "msg" => "课程目录添加失败！"));
        }


    }

    /**
     * 编辑页面
     */
    public function updateCatalog(){
//        $uid = session('loginSession')['user_id'];
        $nid = $_POST['nid'];//目录ID
        $where['catalog_id'] = $nid;
        $whereMap['project_status'] = 1;//审核通过
        $whereMap['project_release'] = 1;//发布成功
//        $whereMap['project_release_user_id'] = $uid;//自己的
        $res = Db::table('up_project_catalog')->where($where)->find();//查询出课程ID
//        $data  = Db::table('up_project')->where($whereMap)->field('project_id,project_name')->select();
//        $this->assign('data',$data);
        $this->assign('res',$res);
        return $this->fetch('study/updateCatalog');
    }

    /***
     *编辑功能
     */
    public function updateCatalogInfo(){
        if($_POST['catalog_id']==''){
            $returnData['status'] = 0;
            $returnData['msg'] = "传递参数错误";
            return json_encode($returnData);
        }else{
            $where['catalog_id'] = $_POST['catalog_id'];
        }

//        $data['catalog_project_id'] = $_POST['catalog_project_id'];
        $data['catalog_name'] = $_POST['catalog_name'];
        $res = Db::table('up_project_catalog')->where($where)->update($data);
        if($res){
            $returnData['status'] = 1;
            $returnData['msg'] = "编辑成功";
            return json_encode($returnData);
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "编辑失败";
            return json_encode($returnData);
        }

    }

    /**
     * 视频列表
     */
    public function getVideo(){
        $whereMap['a.up_course_catalog_id'] = $_POST['video_id'];
        if($_POST['keyword']!=''){
            $keyword  = $_POST['keyword'];
            $whereMap['a.up_course_name'] = array('like',"%$keyword%");
        }
        $rows = $_POST['rows'];
        $page = $_POST['page'];

//        $where['project_status'] = 1;//审核通过
//        $where['project_release'] = 1;//发布成功
//        $res = Db::table('up_project')->where($where)->column('project_id');//查询课程ID
//        if(count($res)>0){
//        $whereS['catalog_project_id'] = array('IN',$res);
//        $project_catalog = Db::table('up_project_catalog')->where($whereS)->column('catalog_id');//查询目录ID
//            if(count($project_catalog)>0){
//        $whereMap['up_course_catalog_id'] = array('IN',$project_catalog);
//            }
//        }
        $result = Db::table('up_project_catalog_course')->alias('a')
            ->join('up_project_catalog up','up.catalog_id = a.up_course_catalog_id','left')
            ->join('up_u_user uuu','uuu.user_id=a.up_course_user_id','left')
            ->join('up_u_admin uua','uua.user_id = a.up_course_user_id','left')
            ->where($whereMap)
            ->field('a.*,up.catalog_name,uuu.user_username,uua.user_username as username')
            ->limit($rows * ($page - 1), $rows)
            ->select();
        $total = Db::table('up_project_catalog_course')->alias('a')
            ->join('up_project_catalog up','up.catalog_id = a.up_course_catalog_id','left')
            ->join('up_u_user uuu','uuu.user_id=a.up_course_user_id','left')
            ->join('up_u_admin uua','uua.user_id = a.up_course_user_id','left')
            ->where($whereMap)
            ->count();
        $data['total'] = $total;
        $data['rows'] = $result;
        return json_encode($data);
    }

    /**
     * 删除视频
     */
    public function delVideo(){
        $cid = $_POST['cid'];
        if($cid!=''){
            $map['up_course_id'] = $cid;
            $data =Db::table('up_project_catalog_course')->where($map)->delete();
            if($data){
                $returnData['status'] = 1;
                $returnData['msg'] = "删除成功";
                return json_encode($returnData);
            }else{
                $returnData['status'] = 0;
                $returnData['msg'] = "删除失败";
                return json_encode($returnData);
            }
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "传递参数错误";
            return json_encode($returnData);
        }
    }

    /**
     * 添加视频页面
     */
    public function addVideo(){
        $res = array();
        $video_id = $_POST['video_id'];
        $catalog_name = Db::table('up_project_catalog')->where('catalog_id',$video_id)->value('catalog_name');
//        $uid = session('loginSession')['user_id'];
//
//        $where['project_status'] = 1;//审核通过
//        $where['project_release'] = 1;//发布成功
//        $where['project_release_user_id'] = $uid;//发布成功
//        $res = Db::table('up_project')->where($where)->column('project_id');//查询课程ID
//
//        $whereS['catalog_project_id'] = array('IN',$res);
//        $project_catalog = Db::table('up_project_catalog')->where($whereS)->select();//查询属于这个团队的所有目录
//        $this->assign('project_catalog',$project_catalog);
        $team_id = Db::table('up_team')->where('is_team',1)->column('team_id');
        if(count($team_id)>0){
            $where['team_id'] = array('IN',$team_id);
            $res = Db::table('up_team_members')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.team_member_user_id')
                ->field('uuu.user_id,uuu.user_phone,uuu.user_username')
                ->where($where)
                ->select();
        }
        $this->assign('catalog_name',$catalog_name);
        $this->assign('res',$res);
        $this->assign('video_id',$video_id);
        return $this->fetch('study/addVideo');

    }
    
    /**
     * 添加视频功能
     */
    public function insertVideo()
    {
        set_time_limit(0);
//        $file = $_FILES['file'];
////        $rand = date('YmdHis').rand(100000,999999);
//        $type = explode('.',$file['name']);
//
//        $filename = './static/aaaaaaa'.'.'.$type[1];//确定上传的文件名
////第一次上传时没有文件，就创建文件，此后上传只需要把数据追加到此文件中
//        if(!file_exists($filename)){
//            move_uploaded_file($_FILES['file']['tmp_name'],$filename);
//        }else{
//            file_put_contents($filename,file_get_contents($_FILES['file']['tmp_name']),FILE_APPEND);
//        }
//        $rand = date('YmdHis').rand(100000,999999);
//        $file = $_FILES['file'];
//        $type = explode('.',$file);
//        var_dump(file_exists('./static/upload.'.$type));die;
//        if($_FILES['file']['error']==0){
//            if(!file_exists('./static/upload.'.$type)){
//                if(!move_uploaded_file($file['tmp_name'],'./static/upload.'.$type)){
//                    echo 'failed';
//                }
//            }else{
//                $content=file_get_contents($file['tmp_name']);
//                if (!file_put_contents('./static/upload.'.$type, $content,FILE_APPEND)) {
//                    echo 'failed';
//                }
//            }
//        }else{
//            echo 'failed';
//        }
//        $exe = explode('.',$_FILES['file']['name']);
//        move_uploaded_file($_FILES['file']['tmp_name'],'./static/'.$rand.$exe);
        if($_POST['up_course_name']==''){
            $returnData['status'] = 0;
            $returnData['msg'] = "视频名称不能为空";
            return json_encode($returnData);
        }
        $uid = session('loginSession')['user_id'];
        $rand = date('YmdHis').rand(100000,999999);
        $exe = explode('.',$_FILES['file']['name']);
        $filePath = $_FILES['file']['tmp_name'];
        $info = $this->qnCommon(5,$rand,$exe[1],$filePath);
        if($info['status']==200){

            $info1 = $this->qnCommon1($info['key']);
            $data['up_course_url'] = QiNiu.$info1['rand'].'.mp4';
            $data['up_course_time'] = number_format($info['vtime'],2,".","");
            $data['up_course_catalog_id'] = $_POST['up_course_catalog_id'];
            $data['up_course_id'] = $this->getRandChar(32);
            $data['up_course_name'] = $_POST['up_course_name'];
            $data['up_course_vedio_time'] = date('Y-m-d H:i:s');
            $data['up_course_user_id'] = $uid;
            $res = Db::table('up_project_catalog_course')->insert($data);
            if($res){
                $fid = Db::table('up_project_catalog')->where('catalog_id',$_POST['up_course_catalog_id'])->value('catalog_project_id');
                $catalog_project_id = Db::table('up_project_catalog')->where('catalog_id',$_POST['up_course_catalog_id'])->field('catalog_project_id')->find();
                if($catalog_project_id['catalog_project_id']!=''){
                    $project_team_id = Db::table('up_project')->where('project_id',$catalog_project_id['catalog_project_id'])->value('project_team_id');
                    if($project_team_id!=''){//证明是团队发布的
                        $team_name = Db::table('up_team')->where('team_id',$project_team_id)->value('team_name');
                        $where1['team_id'] =$project_team_id;
                        $where1['team_member_remove'] =2;
                        $team_member_user_id = Db::table('up_team_members')->where($where1)->column('team_member_user_id');
                        $msg = $team_name.'发布了新的课程';
                        $msg1 = "{\"msg\":\"18\"}";
                        $msg_data =array('msg'=>$msg,'code'=>18,'fid'=>$fid);
                        $code = 18;
                        $code1 = 18;
                        $this->sendJpush(1,$msg,$msg_data,$team_member_user_id,$msg1,$code,1,$code1);
                    }else{
//                        $whereU['user_personal_status'] = 2;
                        $whereU['user_status'] = 1;
                        $up_u_user =Db::table('up_u_user')->where($whereU)->column('user_id');
                        $msg = '平台发布了发布了新的课程';
                        $msg_data =array('msg'=>$msg,'code'=>18,'fid'=>$fid);
                        $msg1 = "{\"msg\":\"18\"}";
                        $code = 18;
                        $code1 = 18;
                        $this->sendJpush(2,$msg,$msg_data,$up_u_user,$msg1,$code,1,$code1);
                    }
                }
                $returnData['status'] = 1;
                $returnData['msg'] = "发布成功";
                return json_encode($returnData);
            }else{
                $returnData['status'] = 0;
                $returnData['msg'] = "发布失败";
                return json_encode($returnData);
            }
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "上传失败";
            return json_encode($returnData);
        }
    }

    /**
     * @return mixed
     * 编辑页面
     */
    public function updateVideo(){
        $uid = session('loginSession')['user_id'];

        $result = Db::table('up_project_catalog_course')->where('up_course_id',$_POST['nid'])->find();
        $where['project_status'] = 1;//审核通过
        $where['project_release'] = 1;//发布成功
        $where['project_release_user_id'] = $uid;//发布成功

        $res = Db::table('up_project')->where($where)->column('project_id');//查询课程ID

        $whereS['catalog_project_id'] = array('IN',$res);
        $project_catalog = Db::table('up_project_catalog')->where($whereS)->select();//查询属于这个团队的所有目录
        $this->assign('project_catalog',$project_catalog);
        $this->assign('res',$result);
        return $this->fetch('study/updateVideo');
    }

    /**
     * @return string
     * 编辑功能
     */
    public function updateVideoInfo(){
        set_time_limit(0);
        if($_POST['up_course_name']==''){
            $returnData['status'] = 0;
            $returnData['msg'] = "视频名称不能为空";
            return json_encode($returnData);
        }
        if(!empty($_FILES['file']['name'])) {
            $rand = date('YmdHis') . rand(100000, 999999);
            $exe = explode('.', $_FILES['file']['name']);
            $filePath = $_FILES['file']['tmp_name'];
            $info = $this->qnCommon(5, $rand, $exe[1], $filePath);
            if ($info['status'] == 200) {
//                $data['up_course_url'] = QiNiu . $info['key'];
                $info1 = $this->qnCommon1($info['key']);
                $data['up_course_url'] = QiNiu.$info1['rand'].'.mp4';
                $data['up_course_time'] = number_format($info['vtime'], 2, ".", "");

            }
        }
        $data['up_course_name'] = $_POST['up_course_name'];
        $where['up_course_id'] = $_POST['up_course_id'];
        $res = Db::table('up_project_catalog_course')->where($where)->update($data);
        if($res){
            $returnData['status'] = 1;
            $returnData['msg'] = "修改成功";
            return json_encode($returnData);
        }else{
            $returnData['status'] = 0;
            $returnData['msg'] = "修改失败";
            return json_encode($returnData);
        }
}


}